﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using Bitis_KeToanThue_Pro_DungChung.Common;

namespace Bitis_KeToanThue_Pro_QuanTri.AccessDatabase
{
    public class DanhMucMenu
    {
        AccessData ac = new AccessData(1);
        public int sua(string tenmenu, string tenmodule, string tenform, string diengiai, string duongdan, int maloaimenu, string tenthumuc,int menuid)
        {
            SqlParameter[] arrPara = new SqlParameter[9];
            arrPara[0] = new SqlParameter("@TenMenu", SqlDbType.NVarChar);
            arrPara[0].Value = tenmenu;
            arrPara[1] = new SqlParameter("@TenModule", SqlDbType.NVarChar);
            arrPara[1].Value = tenmodule;
            arrPara[2] = new SqlParameter("@TenForm", SqlDbType.NVarChar);
            arrPara[2].Value = tenform;
            arrPara[3] = new SqlParameter("@DienGiai", SqlDbType.NVarChar);
            arrPara[3].Value = diengiai;
            arrPara[4] = new SqlParameter("@Hinh", SqlDbType.Image);
            arrPara[4].Value = ClassXuLyChung.ConvertImageToByte(duongdan);
            arrPara[5] = new SqlParameter("@MaLoaiMenu", SqlDbType.Int);
            arrPara[5].Value = maloaimenu;
            arrPara[6] = new SqlParameter("@TenThuMuc", SqlDbType.NVarChar);
            arrPara[6].Value = tenthumuc;
            arrPara[7] = new SqlParameter("@MenuID", SqlDbType.Int);
            arrPara[7].Value = menuid;
            arrPara[8] = new SqlParameter("@DuongDan", SqlDbType.NVarChar);
            arrPara[8].Value = duongdan;

            DataTable dt = ac.ftblDocDuLieuSP("thuan_qtsuamenu", arrPara);
            return int.Parse(dt.Rows[0]["ErrCode"].ToString());
        }
        public int them(string tenmenu,string tenmodule,string tenform,string diengiai,string duongdan,int maloaimenu,string tenthumuc)
        {
            SqlParameter[] arrPara = new SqlParameter[7];
            arrPara[0] = new SqlParameter("@TenMenu", SqlDbType.NVarChar);
            arrPara[0].Value =tenmenu;
            arrPara[1] = new SqlParameter("@TenModule", SqlDbType.NVarChar);
            arrPara[1].Value = tenmodule;
            arrPara[2] = new SqlParameter("@TenForm", SqlDbType.NVarChar);
            arrPara[2].Value = tenform;
            arrPara[3] = new SqlParameter("@DienGiai", SqlDbType.NVarChar);
            arrPara[3].Value = diengiai;
            arrPara[4] = new SqlParameter("@Hinh", SqlDbType.Image);
            arrPara[4].Value = ClassXuLyChung.ConvertImageToByte(duongdan);
            arrPara[5] = new SqlParameter("@MaLoaiMenu", SqlDbType.Int);
            arrPara[5].Value = maloaimenu;
            arrPara[6] = new SqlParameter("@TenThuMuc", SqlDbType.NVarChar);
            arrPara[6].Value = tenthumuc;
            DataTable dt = ac.ftblDocDuLieuSP("thuan_qtthemmenu", arrPara);
            return int.Parse(dt.Rows[0]["ErrCode"].ToString());
        }
        public int xoa(int userid)
        {
            SqlParameter[] arrPara = new SqlParameter[1];
            arrPara[0] = new SqlParameter("@ID", SqlDbType.Int);
            arrPara[0].Value = userid;
            DataTable dt = ac.ftblDocDuLieuSP("thuan_qtxoamenu", arrPara);
            return int.Parse(dt.Rows[0]["ErrCode"].ToString());
        }
        public DataTable loaddulieubyid(int menuid)
        {
            SqlParameter[] arrPara = new SqlParameter[1];
            arrPara[0] = new SqlParameter("@MenuID", SqlDbType.Int);
            arrPara[0].Value = menuid;

            return ac.ftblDocDuLieuSP("thuan_qtloaddanhsachmenubymenuid", arrPara);

        }
        public DataTable loadgrid()
        {
            return ac.ftblDocDuLieuSP("thuan_qtloaddanhsachmenu", null);
        }
        public DataTable loadcomboloaimenu()
        {
            return ac.ftblDocDuLieuSP("thuan_qtloadcomboloaimenu", null);
        }
    }
}
